package com.net.framework.help.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListAdapter;

/****
 * @author Administrator
 */
public class LinearLayoutForListView extends LinearLayout {
    private ListAdapter adapter;

    /**
     * 绑定布局
     */
    public void bindLinearLayout() {
        int count = adapter.getCount();
        this.removeAllViews();
        for (int i = 0; i < count; i++) {
            View v = adapter.getView(i, null, null);
            v.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                }
            });
            this.addView(v, i);
        }
    }

    public void setAdapter(ListAdapter adapter) {
        this.adapter = adapter;
        notifyDataSetChanged();
    }

    /***
     * 刷新视图
     */
    public void notifyDataSetChanged() {
        bindLinearLayout();
    }

    public LinearLayoutForListView(Context context) {
        super(context);
    }

    public LinearLayoutForListView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }
}